<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>EventSource是一种服务器推送技术，它允许服务器向客户端发送消息，而客户端无法向服务器发送消息。这种技术可以用于实现服务器端的实时更新，例如实时股票报价、天气预报、社交媒体通知等。</title>
  <style>
    *,
    *::after,
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    :root {
      min-height: 100vh;
    }

    :root:focus-within {
      scroll-behavior: smooth;
    }

    body {
      min-height: inherit;
    }
  </style>
</head>

<body>
  <div></div>
</body>
<script>
  "use strict"; {
    if (!!window.EventSource) {
      throw new Error(`您的浏览器不支持SSE`);
    };

    let source = new EventSource("/events");
    source.addEventListener("message", e => {
      console.log(e.data);

    });
    source.addEventListener("open", () => {

    });
    source.addEventListener("error", () => {

    });
  };
</script>

</html>